﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PdxDemo
{
    /// <summary>
    /// Interaction logic for ShellView.xaml
    /// </summary>
    public partial class ShellView : UserControl
    {
        public ShellView()
        {
            InitializeComponent();

            Focusable = true;
            IsTabStop = false;
        }

        private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var vm = DataContext as ShellViewModel;
            if (vm == null)
            {
                return;
            }

            var recorder = vm.SelectedScreen.Viewmodel.ChangeRecorder;

            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                if (Keyboard.IsKeyDown(Key.Z) && recorder.CanUndo)
                {
                    e.Handled = true;
                    recorder.Undo();
                }
                else if (Keyboard.IsKeyDown(Key.Y) && recorder.CanRedo)
                {
                    e.Handled = true;
                    recorder.Redo();
                }
            }
        }
    }
}
